package com.luoy.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;

/**
 * 获取pageVO对象
 * 封装了分页信息
 *
 * @author LUOYUAN
 * @create 2018-06-08-下午6:53
 */
@Slf4j
public class Object2PageVOUtil {

    public static <T, S> PageVO<S> get(Integer page, Integer size, T t, Class<S> s) {

        PageVO<S> pageVO = new PageVO<>();
        //封装数据
        try {
            //新建vo对象
            S sVo = s.newInstance();
            //拷贝数据
            BeanUtils.copyProperties(t, sVo);
            //vo放入集合中
            ArrayList<S> screenVOList = new ArrayList<>();
            screenVOList.add(sVo);
            //数据封装到pageVO中
            pageVO.setItems(screenVOList);
            pageVO.setTotal(1);
            pageVO.setCurrentPage(page);
            pageVO.setSize(size);
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return pageVO;
    }
}
